<!--
 * @Author: zhi1hw hanwei@zhi1tech.com
 * @Date: 2024-06-18 10:32:15
 * @LastEditors: zhi1hw hanwei@zhi1tech.com
 * @LastEditTime: 2025-01-06 15:21:26
 * @FilePath: \code\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { themeStore, ITheme } from "./store/modules/theme";
const themeColor: ITheme = themeStore().theme;
import {
  ComponentInternalInstance,
  getCurrentInstance,
  inject,
  onMounted,
  onUnmounted,
  reactive,
  watch,
  defineProps,
  provide,
} from "vue";
// 获取当前主题
const { proxy } = getCurrentInstance() as ComponentInternalInstance;

provide("themeColor", themeColor);
const state = reactive({
  isLoadEnd: false,
});
const isMobile = function () {
  const userAgent = navigator.userAgent.toLowerCase();
  return /iphone|ipod|android|windows phone|blackberry|bb10|mobi|xoom|tablet|mobile/i.test(
    userAgent
  );
};
onMounted(() => {
  if (isMobile()) {
    const screenWidth =
      window.innerWidth ||
      document.documentElement.clientWidth ||
      document.body.clientWidth;
    const isTablet = screenWidth >= 479 && screenWidth <= 1024;
    if (isTablet) {
      var html_ = document.getElementsByTagName("html")[0];
      if (window.innerWidth > window.innerHeight) {
        html_.style.fontSize = "10px";
      } else {
        html_.style.fontSize = "16px";
        // 竖屏
      }
    }
    const s = document.createElement("script");
    s.type = "text/javascript";
    s.src = /wxwork/i.test(navigator.userAgent)
      ? "https://res.wx.qq.com/open/js/jweixin-1.2.0.js"
      : "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
    document.body.appendChild(s);
    if (/wxwork/i.test(navigator.userAgent)) {
      localStorage.setItem("env", "wxwork");
    } else if (/micromessenger/i.test(navigator.userAgent)) {
      localStorage.setItem("env", "micromessenger");
    }
  } else {
    let params: any = proxy?.$utils.getUrlParam();
    let str = process.env.VUE_APP_PC_CHART + '?isFromApp=true';
    if(params?.id_token) {
      str += '&id_token=' + params.id_token;
    }
    if(params?.code || params?.userCode) {
      str += '&userCode=' + params.userCode;
    }
    location.href = str;
    return;
  }
});
</script>

<template>
  <div>
    <van-watermark
      v-if="themeStore().email"
      :content="themeStore().email"
      full-page
      :gap-y="5"
      opacity=".5"
    />
    <router-view> </router-view>
  </div>
</template>

<style lang="scss">
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}
a {
  color: #5cb2ff;
}
</style>
